<%@ page import="com.cdvtc.flower.dao.CategoryDao" %>
<%@ page import="com.cdvtc.flower.dao.impl.CategoryDaoImpl" %>
<%@ page import="com.cdvtc.flower.model.Category" %>
<%@ page import="java.util.List" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page import="com.cdvtc.flower.dao.MerchantsDao" %>
<%@ page import="com.cdvtc.flower.model.Merchants" %>
<%@ page import="com.cdvtc.flower.dao.impl.MerchantsDaoImpl" %>
<%@ page import="com.cdvtc.flower.dao.ProductsDao" %>
<%@ page import="com.cdvtc.flower.dao.impl.ProductsDaoImpl" %>
<%@ page import="com.cdvtc.flower.model.Products" %><%--
  Created by IntelliJ IDEA.
  User: admin
  Date: 2024/5/31
  Time: 18:04
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>商品信息</title>
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <link rel="stylesheet" href="css/main.css">

</head>
<body>
<!--<jsp:include page="commons/header.jsp"></jsp:include>-->
<div class="container">
    <div class="panel panel-info">
        <div class="panel-heading">
            <h3 class="panel-title">
                修改商品信息
            </h3>
        </div>
        <div class="panel-body" style="padding: 20px;">
            <form action="ProductsAddServlet" class="form-horizontal" role="form" method="post" enctype="multipart/form-data">
                <div class="form-group">
                    <%
                        // 这里是一个简化的例子，通常您会使用DAO或Service层来执行此操作
                        ProductsDao productsDao = new ProductsDaoImpl();
                        int nextProductId = productsDao.getNextProductId(); // 获取单个商品
                        // 将商品编号设置为请求范围的属性
                        request.setAttribute("productId", nextProductId);
                    %>
                    <label for="product_id" class="col-sm-2 control-label">商品编号：</label>
                    <div class="col-sm-10">
                        <input type="text" readonly class="form-control" name="product_id" id="product_id" placeholder="请输入商品编号" value="${productId}">
                    </div>
                </div>
                <div class="form-group">
                    <label for="product_name" class="col-sm-2 control-label">名称：</label>
                    <div class="col-sm-10">
                        <input type="text" class="form-control" name="product_name" id="product_name" placeholder="请输入商品名称" value="">
                    </div>
                </div>
                <div class="form-group">
                    <label for="category_id" class="col-sm-2 control-label">种类：</label>
                    <div class="col-sm-10">
                        <%
                            CategoryDao categoryDao = new CategoryDaoImpl();
                            List<Category> categoryList; // 更改变量名以避免混淆
                            categoryList = categoryDao.getAllCategories();
                            pageContext.setAttribute("categoryList", categoryList); // 使用新的变量名
                        %>
                        <select class="form-control" name="category_id" id="category_id">
                            <option value="">请选择商品种类</option>
                            <c:forEach var="category" items="${categoryList}" varStatus="status">
                                <c:choose>
                                    <c:when test="${not empty originalCategoryId and originalCategoryId == category.category_id}">
                                        <!-- 如果当前category的ID等于originalCategoryId，则设置为selected -->
                                        <option value="${category.category_id}" selected="selected">${category.category_name}</option>
                                    </c:when>
                                    <c:otherwise>
                                        <!-- 否则，只是普通的option -->
                                        <option value="${category.category_id}">${category.category_name}</option>
                                    </c:otherwise>
                                </c:choose>
                            </c:forEach>
                        </select>
                    </div>
                </div>
                <div class="form-group">
                    <label for="image" class="col-sm-2 control-label">图片：</label>
                    <div class="col-sm-10">
                        <input type="file" class="form-control" name="image" id="image" placeholder="请选择图片" accept="image/jpg,image/jpeg,image/png" value="">
                    </div>
                </div>
                <div class="form-group">
                    <label for="original_price" class="col-sm-2 control-label">原价：</label>
                    <div class="col-sm-10">
                        <input type="text" class="form-control" name="original_price" id="original_price" placeholder="请输入原价" value="">
                    </div>
                </div>
                <div class="form-group">
                    <label for="sale_price" class="col-sm-2 control-label">售价：</label>
                    <div class="col-sm-10">
                        <input type="text" class="form-control" name="sale_price" id="sale_price" placeholder="请输入售价" value="">
                    </div>
                </div>
                <div class="form-group">
                    <label for="description" class="col-sm-2 control-label">简述：</label>
                    <div class="col-sm-10">
                        <input type="text" class="form-control" name="description" id="description" placeholder="请输入商品简述" value="">
                    </div>
                </div>
                <div class="form-group">
                    <label for="merchant_id" class="col-sm-2 control-label">商家：</label>
                    <div class="col-sm-10">
                        <%
                            MerchantsDao merchantsDao = new MerchantsDaoImpl();
                            List<Merchants> merchantsList; // 更改变量名以避免混淆
                            merchantsList = merchantsDao.getALLMerchants();
                            pageContext.setAttribute("merchantsList", merchantsList); // 使用新的变量名
                        %>
                        <select class="form-control" name="merchant_id" id="merchant_id">
                            <option value="">请选择商家</option>
                            <c:forEach var="merchant" items="${merchantsList}" varStatus="status">
                                <c:choose>
                                    <c:when test="${not empty originalMerchantId and originalMerchantId == merchant.merchant_id}">
                                        <!-- 如果当前category的ID等于originalCategoryId，则设置为selected -->
                                        <option value="${merchant.merchant_id}" selected="selected">${merchant.store_name}</option>
                                    </c:when>
                                    <c:otherwise>
                                        <!-- 否则，只是普通的option -->
                                        <option value="${merchant.merchant_id}">${merchant.store_name}</option>
                                    </c:otherwise>
                                </c:choose>
                            </c:forEach>
                        </select>
                    </div>
                </div>
                <div class="form-group">
                    <label for="sold" class="col-sm-2 control-label">是否上架：</label>
                    <div class="col-sm-10">
                        <select class="form-control" name="sold" id="sold">
                            <option value="${product.sold}">请选择是否上架</option>
                            <option value="true">true</option>
                            <option value="false">false</option>
                        </select>
                    </div>
                </div>

                <div class="form-group">
                    <div class="col-sm-offset-2 col-sm-10">
                        <button type="submit" class="btn btn-default">确定</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
<script src="js/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
</body>
</html>



